using System;
using Microsoft.DirectX.Direct3D;
using System.IO;

namespace SharpWind.Resources.Creators
{
	public class MeshFromFileCreator : IResourceCreator<Mesh>
	{
		private string path = string.Empty;

		public MeshFromFileCreator( string path )
		{
			if( path != null && path != string.Empty && File.Exists( path ) )
			{
				this.path = path;
			}
			else
			{
				throw new Exception();
			}
		}
	
		public Mesh Create()
		{
			ExtendedMaterial[] materials;
			Mesh mesh    = new Mesh();
			mesh.D3DMesh = Microsoft.DirectX.Direct3D.Mesh.FromFile( this.path, 0, Engine.Instance.Renderer.Device, out materials );
			mesh.Subsets = materials.Length;
			
			return mesh;
		}
	}
}
